﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Interfaces;
using System.Configuration;
using DAOExceptions;
using MixedDAO;

namespace DAOBase
{
    public class DAOFacade
    {
        IDAOFactory factory;
        public DAOFacade()
        {
            if (factory != null)
            {
                return;
            }
            var database_mode = ConfigurationManager.AppSettings["DataBaseMode"];
            if (database_mode == null)
                throw new DAOException("Database Mode is null");
            switch (database_mode)
            {
                case "Mixed":
                default:
                    var user_database = ConfigurationManager.AppSettings["UserDataBase_Type"];
                    var role_database = ConfigurationManager.AppSettings["RoleDataBase_Type"];
                    var hostfiles_database = ConfigurationManager.AppSettings["HostFilesDataBase_Type"];
                    var storage_database = ConfigurationManager.AppSettings["StorageDataBase_Type"];
                    factory = new MixedDAOFactory(user_database, role_database, hostfiles_database, storage_database);
                    break;
            }                    
        }

        public IDAOFactory GetFactory()
        {
            return factory;
        }
    }
}
